﻿using System;
using System.Collections.Generic;
using System.Text;
using Sys = Cosmos.System;
using AviumX.AviumCore.Screen;
namespace AviumX
{
    public class Kernel : Sys.Kernel
    {
        protected override void BeforeRun()
        {
            //Start the screen Draws it Invisible
            CreateScreen.TheScreen.Initialize(ScreenX.ScreenSizes.Resolution320);
            //Changes Color to White
            CreateScreen.TheScreen.ClearToSystemColor(ScreenX.SystemColors.White);
            //Buffers it to white.
            CreateScreen.TheScreen.ClearBufferToSystemColor(ScreenX.SystemColors.White);
            //Draw the Boot Logo needs improvment.
            AviumX.AviumCore.Screen.Graphics.Images.AviumXLogo.Draw(CreateScreen.TheScreen.Width / 2 - 32 / 2, CreateScreen.TheScreen.Height / 2 - 34 / 2, ScreenX.SystemColors.CornflowerBlue);
            //buffers it and waits for more.
            CreateScreen.TheScreen.DrawBufferToScreen();
            AviumCore.System.Threading.Sleep.DoSleep(2000);

            //Begin Hardware Loading:

            //Load Mouse
            AviumCore.Hardware.Mouse.Cursor.StartCursor();
            AviumCore.System.Threading.CPUThrottle.SetSpeed(90);
            AviumCore.System.State.CurrentState = AviumCore.System.State.States.Desktop;
            AviumCore.System.Threading.Sleep.DoSleep(1500);
        }

        protected override void Run()
        {
            while (true)
            {
                if (AviumCore.System.Threading.CPUThrottle.Count())
                {
                    if (AviumX.AviumCore.System.State.CurrentState == AviumX.AviumCore.System.State.States.Error)
                    {
                        AviumX.AviumCore.System.Error.ErrorScreen.start();
                        if (AviumX.AviumCore.Hardware.Keyboard.KeyBoardCreated.TheKeyBoard.GetkeyPress() == "r")
                        {
                            AviumX.AviumCore.System.KernalReload.Do();
                        }
                    }
                    if (AviumX.AviumCore.System.State.CurrentState == AviumX.AviumCore.System.State.States.Desktop)
                    {
                        AviumX.AviumCore.Screen.Desktop.Desktop.DoDesktop();
                    }
                    AviumX.AviumCore.Hardware.Mouse.Cursor.DrawCursor();
                    /*
                    * double Buffer
                    */
                    AviumX.AviumCore.Screen.CreateScreen.TheScreen.DrawBufferToScreen();
                }
            }
        }
    }
}
